package com.android.bandroid.core.impl;

import android.content.Context;

import com.android.bandroid.api.model.ApiResponse;
import com.android.bandroid.api.service.Api;
import com.android.bandroid.api.service.impl.ApiImpl;
import com.android.bandroid.api.util.CoreCallbackListener;
import com.android.bandroid.core.CoreService;
import com.android.bandroid.core.util.StringUtils;
import com.android.bandroid.model.LoginResp;

/**
 * 核心层服务实现类
 *
 * Created by Kevin on 2015/11/6.
 */
public class CoreServiceImpl implements CoreService{

    private Context mContext;       //  上下文
    private Api api;                //  接口层对象

    public CoreServiceImpl(Context context) {
        this.mContext = context;
        this.api = new ApiImpl(context);
    }

    /**
     * 登录核心业务方法
     *
     * @param userName 用户名
     * @param password 密码
     * @param listener 回调监听
     */
    @Override
    public void login(String userName, String password, CoreCallbackListener<ApiResponse<LoginResp>> listener) {
            if(StringUtils.isEmpty(userName)){
                if( null != listener){
                    listener.onFailure("0", "用户名为空");
                }
            }
            if(StringUtils.isEmpty(password)){
                if( null != listener){
                    listener.onFailure("1", "密码为空");
                }
            }
        api.loginByApp(userName, password, listener);
    }
}
